package com.itcast.test;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public class StreamTest2 {

    public static void main(String[] args) {
        int[] arrs = {8,5,3,10,9,5,7,6,5,11};

        long count = Arrays.stream(arrs).count();
        System.out.println("个数：" + count);

        int sum = Arrays.stream(arrs).sum();
        System.out.println("求和：" + sum);

        int max = Arrays.stream(arrs).max().getAsInt();
        System.out.println("最大值：" + max);

        int min = Arrays.stream(arrs).min().getAsInt();
        System.out.println("最小值：" + min);

        double avg = Arrays.stream(arrs).average().getAsDouble();
        System.out.println("平均值：" + avg);

        List<Integer> limit = Arrays.stream(arrs).boxed().limit(3).collect(Collectors.toList());
        System.out.println("过滤器");

        List<Integer> listAsc = Arrays.stream(arrs).boxed().sorted((a,b)->a-b).collect(Collectors.toList());
        System.out.println("升序结果：" + listAsc);

        List<Integer> listDesc = Arrays.stream(arrs).boxed().sorted((a,b)->b-a).collect(Collectors.toList());
        System.out.println("升序结果：" + listDesc);

        List<Integer> listFilter = Arrays.stream(arrs).boxed().filter(a -> a > 3).collect(Collectors.toList());
        System.out.println("过滤结果：" + listFilter);

        long countResult = Arrays.stream(arrs).filter(a -> a == (5)).count();
        System.out.println("5出现的次数：" + countResult);
    }
}